package com.jerry.base.java8.lambda;

import java.io.File;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * 方法引用练习
 *
 * @author Jerry
 * @since 2024/7/31 16:36
 */
public class MethodRefExercise {

    record Student(String name) {
    }

    public static void main(String[] args) {

        Function<String, Integer> lambda1 = s -> Integer.parseInt(s);
        Function<String, Integer> ref1 = Integer::parseInt;

        BiPredicate<List<String>, String> lambda2 = (list, element) -> list.contains(element);
        BiPredicate<List<String>, String> ref2 = List::contains;

        BiPredicate<Student, Object> lambda3 = (stu, obj) -> stu.equals(obj);
        BiPredicate<Student, Object> ref3 = Student::equals;

        Predicate<File> lambda4 = file -> file.exists();
        Predicate<File> ref4 = File::exists;

        Runtime runtime = Runtime.getRuntime();

        Supplier<Long> lambda5 = () -> runtime.freeMemory();
        Supplier<Long> ref5 = runtime::freeMemory;
    }
}
